package com.liao.kafka;

import com.liao.dao.HbaseDAO;
import com.liao.utils.PropertyUtil;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class HbaseConsumer {

    public static void main(String[] args) throws Exception {

        //获取kafka消费者
        KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<>(PropertyUtil.properties);

        //从配置文件中获取消费者的主题信息
        kafkaConsumer.subscribe(Arrays.asList(PropertyUtil.properties.getProperty("kafka.topic")));
        System.out.println(kafkaConsumer);

        //设置时间去获取一次消息
        HbaseDAO hbaseDao = new HbaseDAO();
        while (true){
            ConsumerRecords<String, String> records = kafkaConsumer.poll(300);
            for (ConsumerRecord<String, String> record : records) {

                String ori = record.value();
                System.out.println(ori);
                hbaseDao.put(ori);

            }
        }
    }
}